#include "PrecompiledHeaders.h"
#include "Utilities.h"
#include <time.h>
#include <stdlib.h>
#include <fstream>


#ifdef WIN32

// windows version of functions
#include <windows.h>

double getCurrentTime()
{
    return (double)clock() / CLOCKS_PER_SEC;
}

void wait(double duration)
{
    Sleep((unsigned int)(duration * 1000));
}

#else

// linux version of functions
#include <unistd.h>

double getCurrentTime()
{
    return (double)clock() / CLOCKS_PER_SEC;
}

void wait(double duration)
{
    sleep((unsigned int)(duration));
}

#endif

/*
 * Generate a random numerical string of length n
 */
char *randomString(char* s, size_t n)
{
    // 48:0, 57:9
    srand((unsigned)time(0));
    for(unsigned int i=0; i<n; i++) {
        s[i] = 48 + (rand() % 10);
    }
    s[n] = '\0';
    return s;
}

bool fileExists(const std::string& fileName)
{
  std::fstream fin;
  fin.open(fileName.c_str(),std::ios::in);
  if( fin.is_open() )
  {
    fin.close();
    return true;
  }
  fin.close();
  return false;
}
